void httpGet(clientRequestTask *t)
{
    sprintf(t->path, "%s%s", t->xp->path, t->uri);
    if (t->path[strlen(t->path) - 1] == '/')
        strcat(t->path, "index.html");

    struct stat st;
    if (stat(t->path, &st) == -1) {
        httpNotFound(t);
    }
    else {
        if ((st.st_mode & S_IFMT) == S_IFDIR)
            strcat(t->path, "/index.html");

        FILE *resource = fopen(t->path, "r");
        if (resource == NULL)
            httpNotFound(t);
        else {
            char *ext = strrchr(t->path, '.'); /* extension */
            char *ct = getMimesConfig(ext ? ext + 1: "html");

            httpStatus(t, 200, "OK");
            httpHeader(t, "Content-Type", ct ? ct : "text/html");
            httpHeader(t, "Connection", "close");
            httpBody(t, "\r\n");

            if (t->lwritten > 0) {
                int out_fd = fileno(resource);
                int result;
                for (;;) {
                    result = sendfile(t->fd, out_fd, NULL, 512);
                    if (result == 0)
                        break;
                    else if (result == -1)
                    if (errno == EAGAIN && t->exit == 0) {
                        sem_wait(&(t->sem));
                        continue;
                    }
                }
            }

            fclose(resource);
        }
    }
}
